package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.zzyl.entity.User;
import com.zzyl.mapper.UserMapper;
import com.zzyl.vo.UserAuth;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.stereotype.Service;

@Service
public class UserDetailServiceImpI implements UserDetailsService {
    @Autowired
    private UserMapper userMapper;
/**
 * @author     ：zhangheng
 * @date       ：Created in 2024/9/8 11:00
 * @description：登录接口实现类
 * @modified By：
 * @version: 1.0
 */
@Override
public UserDetails loadUserByUsername(String username) {
    User user = userMapper.fingUserVoLogin(username);
    if (user == null || user.getDataState().equals("1")) {
        throw new RuntimeException("用户登录异常");
    }
    //将单个对象复制到需要返回的类中（个实体类的对象转换为一个DTO（数据传输对象）或者VO（视图对象（支持单个对象间的复制））
    return BeanUtil.toBean(user, UserAuth.class);

}
}

